home *** CD-ROM | disk | FTP | other *** search
Java Source | 1995-12-31 | 1.9 KB | 65 lines |
-
- import java.awt.*;
-
- public class ClipRect extends DoubleBuff implements Runnable {
-
- boolean drewall = false; // whole screen drawn yet?
-
-
-
- /* The paint method */
- public void paint(Graphics g) {
-
- if (!drewall) g.clipRect(0,0,XRES,YRES);
- else
- if (y > oldy) g.clipRect(x,oldy,w+1,y+h);
- else
- g.clipRect(x,y,w+1,oldy+h);
-
-
- dbuffer.setColor(Color.lightGray); // background color
- dbuffer.fillRect(x,oldy,w+1,h+1); // cover up last box drawn
- oldy=y; // remember y for the next coverup
-
- /* draw background pattern */
- for(int gc=0;gc<XRES;gc+=gw) {
- dbuffer.setColor(Color.gray); // color of gridlines
- dbuffer.drawLine(gc,0,gc,YRES); // draw vertical lines
- dbuffer.drawLine(0,gc,XRES,gc); // draw horizontal lines
- dbuffer.setColor(Color.yellow); // set color to yellow
- dbuffer.drawLine(gc,0,0,gc); // draw diags
- dbuffer.setColor(Color.blue); // set color to blue
- dbuffer.drawLine(XRES-gc,0,XRES,gc); // draw diags
- }
-
- dbuffer.setColor(Color.lightGray); // background color
- dbuffer.fillRect(0,0,100,20); // clear box for title
- dbuffer.setColor(Color.red); // set color to red
- dbuffer.drawString("SingleBuffer",0,10);
- dbuffer.fillRect(x,y,w,h); // draw red square
- dbuffer.setColor(Color.blue);
-
- int l=0;
- for (int lh=h;lh>0;l+=4,lh-=8)
- dbuffer.drawOval(x+l,y+l,lh,lh);
-
- /* Notice that the only call to the g object */
- /* is on the following line. All other graphics */
- /* operations happen to the buffer */
-
- /* Transfer (blit) the offscreen to the screen */
- g.drawImage(offscreen,0,0,this);
- drewall = true;
-
- }
-
- public void start() {
- drewall = false;
- if (MyThread == null) {
- MyThread = new Thread(this);
- MyThread.start();
- }
- }
-
- }
-